Skip to content

Enabler for rust log to be used in S-CORE#6

Open
pawelrutkaq wants to merge 4 commits intoeclipse-score:mainfrom
qorix-group:pawelrutkaq_initial_log_interface
Open

Enabler for rust log to be used in S-CORE#6
pawelrutkaq wants to merge 4 commits intoeclipse-score:mainfrom
qorix-group:pawelrutkaq_initial_log_interface

Conversation

@pawelrutkaq
Copy link

@pawelrutkaq pawelrutkaq commented Aug 21, 2025

Closes #5

@pawelrutkaq pawelrutkaq force-pushed the pawelrutkaq_initial_log_interface branch from b4f3e69 to c537c0a Compare August 21, 2025 05:58
Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
Import from log crate 3aa1359e926a39f841791207d6e57e00da3e68e2
at https://github.com/rust-lang/log

Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
@pawelrutkaq pawelrutkaq force-pushed the pawelrutkaq_initial_log_interface branch from c537c0a to f98cdb1 Compare August 21, 2025 05:59
@vinodreddy-g vinodreddy-g requested review from arsibo and removed request for arsibo August 21, 2025 06:04
@pawelrutkaq pawelrutkaq force-pushed the pawelrutkaq_initial_log_interface branch from f98cdb1 to d718849 Compare August 22, 2025 06:03
Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
Copy link

@darkwisebear darkwisebear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: This looks like a copy & paste from the original log crate. Why not just use that one or re-use / re-export parts? Are there any changes to the crate? If yes, can you please point them out? We can then see how we can integrate those without running into a maintenance nightmare.

}

/// Sets the context for currently build logger.
pub fn context(mut self, context: &str) -> Self {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be called with_context imo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

/// Returns a slice to filled part of buffer. This is not null-terminated.
fn as_c_str(&self) -> &[c_char] {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a misnomer: Since it is not null-terminated, it's also not a C string.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, changed name


/// Returns a slice to filled part of buffer. This is not null-terminated.
fn as_c_str(&self) -> &[c_char] {
unsafe { core::slice::from_raw_parts(self.buf.as_ptr().cast::<c_char>(), self.len()) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add a SAFETY comment that explains why this is actually safe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

const fn is_utf8_char_boundary(i: u8) -> bool {
// This is bit magic equivalent to: b < 128 || b >= 192

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is a copy from the standard lib, but why doing magic if you could just write it like that? The Rust safe coding guidelines will prohibit such casts anyway, so I suggest to turn your comment into code :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's just 2 compares versus one optimization. Not sure what Rust safe coding has to do here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that at some point this library will be used in a safe process. It then needs to comply to the Rust safety guidelines that are being developed. This construct would not be allowed, so sooner or later this has to either be suppressed or be changed.

}
}

struct BufWriter<const BUF_SIZE: usize> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document what the purpose of this thing is. From reverse engineering the code, it seems you manage a preallocated buffer by copying as many UTF8 bates into the buffer as possibly can fit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

log_fn: fn(&mut BufWriter<MSG_SIZE>, &Record),
}

// SAFETY: The underlying C++ logger is assumed to be safe to change thread

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"assumed" is a bit weak. Turn it into "known" if you know.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#include "score/mw/log/logger.h"
#include "score/mw/log/log_level.h"

namespace score

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please collapse namespaces here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

extern "C"
{

Logger *mw_log_create_logger(const char *context)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an equivalent delete?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No as Loggers are maintaned by logging.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it should probably be called "mw_log_get_logger" so that it's clear that this is a non-owning pointer. Maybe you should also elaborate on the lifetime of the pointer.


void mw_log_fatal_logger(const Logger *logger, const char *message, uint32_t size)
{
logger->LogFatal() << LogString{message, size};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use std::string_view, should be the cleaner way.

Copy link
Author

@pawelrutkaq pawelrutkaq Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is better as logging says that This class only supports the logging of the following basic data types:: ..., std::string_view (via implicit conversion to mw::log::LogString) so we skip one hop now.


extern "C" {

pub(crate) fn mw_log_create_logger(context: *const c_char) -> *const Logger;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The returned value is of type *mut Logger in C++.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pawelrutkaq
Copy link
Author

General comment: This looks like a copy & paste from the original log crate. Why not just use that one or re-use / re-export parts? Are there any changes to the crate? If yes, can you please point them out? We can then see how we can integrate those without running into a maintenance nightmare.

SInce the idea was to break dep to log crate. As there is ongoing rewrite co S-CORE forontend, this is just enabler with clear copy place and location in commit. So there is NO maitenance assumed as this will dissappear and new frontend will only be compatible with log crate.

Signed-off-by: Pawel Rutka <pawel.rutka.ext@qorix.ai>
@darkwisebear
Copy link

General comment: This looks like a copy & paste from the original log crate. Why not just use that one or re-use / re-export parts? Are there any changes to the crate? If yes, can you please point them out? We can then see how we can integrate those without running into a maintenance nightmare.

SInce the idea was to break dep to log crate. As there is ongoing rewrite co S-CORE forontend, this is just enabler with clear copy place and location in commit. So there is NO maitenance assumed as this will dissappear and new frontend will only be compatible with log crate.

It seems that S-CORE wants to deviate from the canonical Rust way of logging, which is the log crate. When doing so, there should be a clear statement which use cases are (and always will be) unsupported by the standard front end. Plus we always should also support the standard crate by implementing a backend that also supports it. Is that the case?

@pawelrutkaq
Copy link
Author

pawelrutkaq commented Sep 15, 2025

General comment: This looks like a copy & paste from the original log crate. Why not just use that one or re-use / re-export parts? Are there any changes to the crate? If yes, can you please point them out? We can then see how we can integrate those without running into a maintenance nightmare.

SInce the idea was to break dep to log crate. As there is ongoing rewrite co S-CORE forontend, this is just enabler with clear copy place and location in commit. So there is NO maitenance assumed as this will dissappear and new frontend will only be compatible with log crate.

It seems that S-CORE wants to deviate from the canonical Rust way of logging, which is the log crate. When doing so, there should be a clear statement which use cases are (and always will be) unsupported by the standard front end. Plus we always should also support the standard crate by implementing a backend that also supports it. Is that the case?

The log crate is not maintaned really in OSSC. Most of things has went into tracing or others. The ideas is that we will provide log crate compatible interface (macros) + S-CORE extensions (ie context passing via macro so DLT can be happy without a need for custom instances ie.). Since log is not certifable, we wont support it like that I think. Thats why it's enabler - otherwise we need to wait longer time for implementation and everone around would use random logging.

@pawelrutkaq
Copy link
Author

pawelrutkaq commented Sep 16, 2025

@arsibo @rmaddikery @hoppe-and-dreams my understanding

  • mw_log_subscriber can go to logging repo once it's created
  • mw_log has to go to baselibs
    Then we have "clear" start point and can continue with proper impl.

@darkwisebear
Copy link

It seems that S-CORE wants to deviate from the canonical Rust way of logging, which is the log crate. When doing so, there should be a clear statement which use cases are (and always will be) unsupported by the standard front end. Plus we always should also support the standard crate by implementing a backend that also supports it. Is that the case?

The log crate is not maintaned really in OSSC. Most of things has went into tracing or others. The ideas is that we will provide log crate compatible interface (macros) + S-CORE extensions (ie context passing via macro so DLT can be happy without a need for custom instances ie.). Since log is not certifable, we wont support it like that I think. Thats why it's enabler - otherwise we need to wait longer time for implementation and everone around would use random logging.

OSSC == Open source scan converter..?

Before deciding to fork the crate (which is effectively what's happening here) we should clarify with upstream whether the necessary changes would be accepted here. Therefore we should collect the known additional parts and open issues upstream. So my questions would be

  • What do we need in addition to what the log crate offers feature-wise?
  • What makes us believe that the crate cannot be qualified / what would need to be changed in order to make it qualifiable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enabler for logging in Rust at S-CORE

2 participants